/*
 * @Author: hexudong 1264275442@qq.com
 * @Date: 2023-04-11 17:58:25
 * @LastEditors: hexudong 1264275442@qq.com
 * @LastEditTime: 2023-04-20 10:43:58
 * @FilePath: /worker_supervision_oa/src/components/BorrowDetail/processModal.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Form, Radio, Input, DatePicker, Button, message } from 'antd';
import FileUpload from '@/components/FileUpload';
import { handleFileid } from '@/utils/utils';
import React, { } from 'react';
import 'moment/locale/zh-cn';
import locale from 'antd/es/date-picker/locale/zh_CN';
import { sendBorrowCheck } from '@/services/public'
import moment from 'moment';

const FormItem = Form.Item;
const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 },
};

interface ProcessModalProps {
    detailMessage: any;
    onSubmit: () => void
}
const ProcessModal: React.FC<ProcessModalProps> = ({ detailMessage, onSubmit }) => {
    const [form] = Form.useForm();
    const checkValue = Form.useWatch('check', form);
    // const disabledDate = (current:Moment) => {
    //     console.log(222);
    //     console.log(form,'form');

    //     const fieldsValue: any = form.validateFields();
    //     return current&& current < moment(fieldsValue.startTime)
    // };
    const tailLayout = {
        wrapperCol: { offset: 8, span: 8 },
    };
    const reconfirm = async () => {
        try {
            const fieldsValue: any = await form.validateFields();
            const params = {
                id: detailMessage.id,
                check: fieldsValue.check,
                startTime: fieldsValue.check == 1 ? fieldsValue.startTime : '',
                endTime: fieldsValue.check == 1 ? fieldsValue.endTime : '',
                remark: fieldsValue.remark,
                checkFileId: fieldsValue.check == 1 ? (fieldsValue.checkFileId ? handleFileid(fieldsValue.checkFileId) : '') : ''
            }
            if (fieldsValue.startTime) {
                params.startTime = moment(fieldsValue.startTime).format('x');
            }
            if (fieldsValue.endTime) {
                params.endTime = moment(fieldsValue.endTime).format('x');
            }
            let res = await sendBorrowCheck(params)
            if (res && res.success) {
                // history.goBack()
                onSubmit();
            } else {
                message.error(res.errMsg || '');
            }


        } catch (error) {

        }
    }
    return (
        <>

            <Form {...formItemLayout} name="save_project" form={form}>
                <FormItem
                    label="审核意见"
                    name="check"
                    initialValue={1}
                    rules={[{ required: true, message: '请选择审核意见！' }]}
                >
                    <Radio.Group>
                        <Radio value={1}>发放成功</Radio>
                        <Radio value={0}>拒绝发放</Radio>
                    </Radio.Group>
                </FormItem>
                {
                    checkValue == 1 && (
                        <>
                            <FormItem
                                label="贷款开始日期"
                                name="startTime"
                                rules={[{ required: true, message: '请选择贷款开始日期！' }]}
                            >
                                <DatePicker
                                    style={{ width: '100%' }}
                                    format={'YYYY-MM-DD'}
                                    placeholder="请选择应还款日期"
                                    locale={locale}
                                />
                            </FormItem>
                            <FormItem
                                label="应还款日期"
                                name="endTime"
                                rules={[{ required: true, message: '请选择应还款日期！' }]}
                            >
                                <DatePicker
                                    style={{ width: '100%' }}
                                    format={'YYYY-MM-DD'}
                                    placeholder="请选择应还款日期"
                                    locale={locale}
                                />
                            </FormItem>


                            <FormItem
                                label="发放凭证"
                                name="checkFileId"
                                initialValue={[]}
                                rules={[{ required: true, message: '请上传发放凭证！' }]}
                            >
                                <FileUpload ossEnum="PROJECT" multiple={true} max={6} type="image/*,.pdf,.doc,.docx" />
                            </FormItem>
                        </>
                    )
                }

                <FormItem label="审核备注" name="remark" initialValue="" >
                    <Input.TextArea showCount maxLength={100} />
                </FormItem>
                <FormItem {...tailLayout} style={{ textAlign: 'center' }}>
                    {/* <Button type="primary">取消</Button> */}
                    <Button type="primary" onClick={() => reconfirm()}>确定</Button>
                </FormItem>
            </Form>
        </>
    );
};

export default ProcessModal;